package o;

import android.app.Activity;
import android.content.Context;
import androidx.annotation.Nullable;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.downloadengine.api.SplitTask;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.application.pkgmanage.model.update.ApkUpgradeInfo;
import com.huawei.appgallery.foundation.card.base.bean.BaseDistCardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.button.DownloadButton;
import com.huawei.appgallery.productpurchase.api.ProductDetailBean;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailHiddenBean;
import com.huawei.appmarket.service.appmgr.view.activity.InstallManagerCardBean;
import java.util.ArrayList;
import java.util.List;
import o.ewm.n;

class dka {
    private SessionDownloadTask ʼ;
    private boolean ˊ = false;
    private DownloadButton ˋ;
    private boolean ˎ = false;
    private BaseDistCardBean ˏ;
    private Context ॱ;
    private dkf ॱॱ;

    class a implements ewe {
        final /* synthetic */ dka ˊ;

        private a(dka o_dka) {
            this.ˊ = o_dka;
        }

        public void ॱ() {
            Logger.ˎ("DownloadUtil", "dialog closed by click back button!");
            this.ˊ.ॱॱ.ॱ();
        }
    }

    class b implements o.dju.b {
        final /* synthetic */ dka ॱ;

        private b(dka o_dka) {
            this.ॱ = o_dka;
        }

        public void ॱ(BaseDistCardBean baseDistCardBean, boolean z) {
            SessionDownloadTask ˎ = this.ॱ.ˏ(this.ॱ.ʼ, baseDistCardBean);
            if (z) {
                djz.ˏ(baseDistCardBean.ˊˊ(), new e(this.ॱ, ˎ));
            } else {
                this.ॱ.ˏ(ˎ);
            }
        }

        public void ˎ() {
            this.ॱ.ॱॱ.ॱ();
        }
    }

    class c implements o.djr.e {
        final /* synthetic */ dka ˋ;

        private c(dka o_dka) {
            this.ˋ = o_dka;
        }

        public void ॱ(Context context, BaseDistCardBean baseDistCardBean) {
            dju o_dju = new dju();
            o_dju.ˏ(new b());
            o_dju.ˊ(this.ˋ.ॱ, baseDistCardBean);
        }

        public void ˋ() {
            this.ˋ.ॱॱ.ॱ();
        }
    }

    class d implements o.ejj.b {
        final /* synthetic */ dka ˎ;

        private d(dka o_dka) {
            this.ˎ = o_dka;
        }

        public void ˊ() {
            this.ˎ.ॱॱ.ॱ();
        }

        public void ॱ() {
            this.ˎ.ॱॱ.ॱ();
        }

        public void ˏ() {
            this.ˎ.ॱॱ.ॱ();
        }
    }

    class e implements o.djz.c {
        final /* synthetic */ dka ˋ;
        private SessionDownloadTask ˎ;

        public e(dka o_dka, SessionDownloadTask sessionDownloadTask) {
            this.ˋ = o_dka;
            this.ˎ = sessionDownloadTask;
        }

        public void ॱ(@Nullable List<o.djz.b> list) {
            if (!CollectCheck.isEmpty((List) list)) {
                List arrayList = new ArrayList();
                for (o.djz.b bVar : list) {
                    if (!(bVar == null || bVar.ॱ() == null)) {
                        this.ˋ.ˏ(bVar.ˋ(), bVar.ॱ().ˋ());
                        arrayList.add(bVar.ˋ());
                    }
                }
                this.ˎ.ॱ(arrayList);
            }
            this.ˋ.ˏ(this.ˎ);
        }
    }

    class f implements o.dqw.c {
        final /* synthetic */ dka ˊ;

        private f(dka o_dka) {
            this.ˊ = o_dka;
        }

        public void ˋ(SessionDownloadTask sessionDownloadTask) {
            this.ˊ.ʼ = sessionDownloadTask;
            Logger.ˎ("DownloadUtil", "start checkPermission.");
            new dts(this.ˊ.ˏ.ˏͺ(), this.ˊ.ˏ.ॱـ(), this.ˊ.ˏ.v_(), new h()).ˋ(this.ˊ.ॱ);
        }

        public void ॱ() {
            Logger.ˋ("DownloadUtil", "AppBundleDownloadListener fail.");
            this.ˊ.ॱॱ.ॱ();
        }
    }

    class g implements o.ewd.c {
        final /* synthetic */ dka ॱ;

        private g(dka o_dka) {
            this.ॱ = o_dka;
        }

        public void ˋ(Context context) {
            new dqw().ˏ(this.ॱ.ˏ, new f());
        }

        public void ˎ() {
            this.ॱ.ॱॱ.ॱ();
        }
    }

    class h implements o.dts.e {
        final /* synthetic */ dka ˊ;

        private h(dka o_dka) {
            this.ˊ = o_dka;
        }

        public void ˎ(Context context, int i) {
            djr o_djr = new djr();
            o_djr.ˊ(new c());
            o_djr.ॱ(context, this.ˊ.ˏ);
        }

        public void ॱ(Context context) {
            this.ˊ.ॱॱ.ॱ();
        }
    }

    protected dka(Context context, DownloadButton downloadButton, boolean z, boolean z2, BaseDistCardBean baseDistCardBean, dkf o_dkf) {
        this.ॱ = context;
        this.ˋ = downloadButton;
        this.ˎ = z;
        this.ˊ = z2;
        this.ˏ = baseDistCardBean;
        this.ॱॱ = o_dkf;
    }

    protected boolean ˏ() {
        int i = 0;
        String ʾ = this.ˏ.ʾ();
        if (ʾ == null || ʾ.length() <= 0) {
            evk.ˋ(this.ॱ, this.ॱ.getResources().getString(n.ꜟˎ), 0).ˋ();
            return false;
        }
        this.ॱॱ.ˎ();
        if ((dug.ॱ(this.ˏ.ॱـ()) == null) && UserSession.getInstance().isUserMinor() && UserSession.getInstance().getUserAge() < this.ˏ.ʻॱ() && eqp.ᐝ()) {
            i = 1;
        }
        if (i != 0) {
            new ewd(this.ॱ, this.ˏ, o.ewd.e.DOWNLOAD_APP, new g()).ˋ();
            return true;
        }
        new dqw().ˏ(this.ˏ, new f());
        return true;
    }

    protected void ˊ() {
        boolean ˏ;
        dwk o_dwk = new dwk();
        o_dwk.ॱ(this.ˋ.ʽ());
        SessionDownloadTask ˋ = dvt.ˏ().ˋ(this.ˏ.ॱـ());
        if (this.ˏ instanceof InstallManagerCardBean) {
            ˋ = dvt.ˏ().ˎ(((InstallManagerCardBean) this.ˏ).ॱ());
        }
        if (ˋ == null) {
            ˏ = ˏ();
        } else if (dsl.ˎ(this.ˏ.ॱـ())) {
            evk.ˋ(this.ॱ, this.ॱ.getString(n.ʽˈ), 0).ˋ();
            new eaw(this.ˏ.ॱـ(), o.eaw.c.COMMAND_CANCLE_DOWNLOADING_TASK).start();
            ˏ = false;
        } else {
            o.dwk.h hVar = new o.dwk.h();
            hVar.ˊ(this.ॱ);
            hVar.ˏ(ˋ);
            hVar.ˏ(new a());
            ˏ = o_dwk.ॱ(hVar);
        }
        if (ˏ) {
            this.ˋ.setEnabled(false);
        }
        Logger.ˏ("DownloadUtil", "download button downloadApp state : RESUME_DONWLOAD_APP");
    }

    protected void ॱ() {
        if (this.ˏ instanceof InstallManagerCardBean) {
            dvt.ˏ().ˏ(((InstallManagerCardBean) this.ˏ).ॱ());
        } else {
            SessionDownloadTask ˋ = dvt.ˏ().ˋ(this.ˏ.ॱـ());
            if (ˋ != null) {
                dvt.ˏ().ˏ(ˋ.ʾ());
            } else {
                Logger.ˋ("DownloadUtil", "downloadButtonTask == null cardBean.getPackage_()=" + this.ˏ.ॱـ());
            }
        }
        Logger.ˏ("DownloadUtil", "download button downloadApp state : PAUSE_DOWNLOAD_APP");
    }

    @Nullable
    private SessionDownloadTask ˏ(SessionDownloadTask sessionDownloadTask, BaseDistCardBean baseDistCardBean) {
        if (sessionDownloadTask == null) {
            Logger.ˋ("DownloadUtil", "compseSessionDownloadTask sessionDownloadTask is null.");
            return null;
        }
        if (CollectCheck.isEmpty(sessionDownloadTask.ᐝˊ())) {
            SplitTask splitTask = new SplitTask();
            splitTask.ˋ(baseDistCardBean.ʾ());
            splitTask.ˊ(baseDistCardBean.ʼॱ());
            splitTask.ˊॱ(baseDistCardBean.ॱـ());
            splitTask.ˋ(baseDistCardBean.ˉ());
            sessionDownloadTask.ˏ(splitTask);
        }
        sessionDownloadTask.ˊ(baseDistCardBean.ʾ());
        sessionDownloadTask.ॱॱ(baseDistCardBean.v_());
        sessionDownloadTask.ʼ(baseDistCardBean.ॱـ());
        sessionDownloadTask.ॱ(baseDistCardBean.ͺˏ());
        sessionDownloadTask.ʽ(baseDistCardBean.ॱˌ());
        sessionDownloadTask.ˏ(baseDistCardBean.ॱॱ());
        sessionDownloadTask.ᐝ(baseDistCardBean.u_());
        sessionDownloadTask.ॱˊ("familyShare=" + baseDistCardBean.ᐝ());
        sessionDownloadTask.ˊ(dgm.ˎ((Activity) this.ॱ));
        sessionDownloadTask.ˎ(baseDistCardBean.ᐝᐝ());
        sessionDownloadTask.ॱ(baseDistCardBean.ˏॱ());
        sessionDownloadTask.ॱˊ(baseDistCardBean.ॱᶥ());
        if (baseDistCardBean.ᐝˊ() != null) {
            sessionDownloadTask.ॱˊ("trackId=" + dof.ˎ(baseDistCardBean.ᐝˊ()));
        } else {
            Logger.ˎ("DownloadUtil", "trackId is null");
        }
        int i = 0;
        try {
            i = Integer.parseInt(baseDistCardBean.ˎˎ());
        } catch (NumberFormatException e) {
            Logger.e("DownloadUtil", "version code error " + e.toString());
        }
        sessionDownloadTask.ʻ(i);
        if (this.ˎ) {
            sessionDownloadTask.ˏ(4);
        }
        sessionDownloadTask.ˎ(baseDistCardBean.ॱʼ());
        ˊ(sessionDownloadTask, i, dug.ॱ(this.ˏ.ॱـ()));
        if (baseDistCardBean instanceof DetailHiddenBean) {
            DetailHiddenBean detailHiddenBean = (DetailHiddenBean) baseDistCardBean;
            if (detailHiddenBean.ॱ() == 1) {
                sessionDownloadTask.ˏ(1);
            }
            sessionDownloadTask.ˋॱ(detailHiddenBean.ﹳ());
            sessionDownloadTask.ͺ(detailHiddenBean.ﾟ());
            sessionDownloadTask.ˏॱ(detailHiddenBean.ﾞ());
            sessionDownloadTask.ॱˊ(baseDistCardBean.ᐨ());
            sessionDownloadTask.ˋॱ(detailHiddenBean.ʼˊ());
            ॱ(sessionDownloadTask, detailHiddenBean);
        }
        if (!(baseDistCardBean instanceof ProductDetailBean)) {
            return sessionDownloadTask;
        }
        ProductDetailBean productDetailBean = (ProductDetailBean) baseDistCardBean;
        if (productDetailBean.ॱ() == null) {
            return sessionDownloadTask;
        }
        sessionDownloadTask.ॱˊ("productNo=" + productDetailBean.ॱ());
        return sessionDownloadTask;
    }

    private void ॱ(SessionDownloadTask sessionDownloadTask, DetailHiddenBean detailHiddenBean) {
        if ((detailHiddenBean.ʼˋ() & 1) != 0 && detailHiddenBean.ʼˊ() == 8 && String.valueOf(1).equals(sessionDownloadTask.ॱˎ("advPlatform")) && dkb.ˏ(sessionDownloadTask) < 157286400) {
            sessionDownloadTask.ˏ(true);
        }
    }

    private void ˊ(SessionDownloadTask sessionDownloadTask, int i, ApkUpgradeInfo apkUpgradeInfo) {
        if (apkUpgradeInfo != null && apkUpgradeInfo.ʿ() >= i) {
            List ᐝˊ = sessionDownloadTask.ᐝˊ();
            if (!CollectCheck.isEmpty(ᐝˊ)) {
                SplitTask splitTask = (SplitTask) ᐝˊ.get(0);
                if (apkUpgradeInfo.ʼ() > 0) {
                    splitTask.ॱ(apkUpgradeInfo.ʼ());
                    splitTask.ˏ(apkUpgradeInfo.ॱॱ());
                    splitTask.ˎ(apkUpgradeInfo.ˈ());
                    splitTask.ˋ(apkUpgradeInfo.ʽॱ());
                }
                sessionDownloadTask.ˊ(apkUpgradeInfo.ʽॱ());
            }
            sessionDownloadTask.ʻ(apkUpgradeInfo.ʿ());
            sessionDownloadTask.ˏ(apkUpgradeInfo.ˊᐝ());
            sessionDownloadTask.ॱ(apkUpgradeInfo.ˏˎ());
        }
    }

    private void ˏ(SessionDownloadTask sessionDownloadTask) {
        dwk o_dwk = new dwk();
        o_dwk.ॱ(this.ˋ.ʽ());
        o_dwk.ˊ(new d());
        o.dwk.h hVar = new o.dwk.h();
        hVar.ˊ(this.ॱ);
        hVar.ˏ(sessionDownloadTask);
        hVar.ˏ(new a());
        if (!o_dwk.ˏ(this.ˊ, hVar)) {
            this.ॱॱ.ॱ();
            Logger.e("DownloadUtil", "startTask failed:" + sessionDownloadTask);
        }
    }
}
